package com.heima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
@WebServlet("/regist")
public class Regist extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取客户端的数据
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String age = req.getParameter("age");
        String phoe = req.getParameter("phoe");
        //获取路径
        String path = this.getServletContext().getRealPath("/");
        //将获取的user对象写入到服务本地
        BufferedWriter bw=new BufferedWriter(new FileWriter(path+"/b.txt",true));
        bw.write(username+","+password+","+age+","+phoe);
        bw.newLine();
        bw.flush();
        bw.close();
        resp.sendRedirect("/loginSucsseful.html");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
